package com.yanqu.road.dao.impl.channelcenter.luckydraw;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.luckydraw.LuckyDrawRewardConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class LuckyDrawRewardConfigDaoImpl extends TempDao {

    private static String getLuckyDrawRewardConfigSql = "select * from `t_n_activity_washepvp_draw` where `activityId`=?";

    public List<LuckyDrawRewardConfig> getLuckyDrawRewardConfigList(int activityId) {
        List<LuckyDrawRewardConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            call = getDb().getConnection().prepareCall(getLuckyDrawRewardConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LuckyDrawRewardConfig luckyDrawRewardConfig = new LuckyDrawRewardConfig();
                luckyDrawRewardConfig.setActivityId(rs.getInt("activityId"));
                luckyDrawRewardConfig.setShootId(rs.getInt("shootId"));
                luckyDrawRewardConfig.setReward(rs.getString("reward"));
                luckyDrawRewardConfig.setNum(rs.getInt("num"));
                luckyDrawRewardConfig.setWeight(rs.getInt("weight"));
                luckyDrawRewardConfig.setPlace(rs.getInt("place"));
                list.add(luckyDrawRewardConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
